package cn.smbms.service.user;

import cn.smbms.dao.user.UserMapper;
import cn.smbms.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//@Transactional
@Scope
@Service("userService")
public class UserServiceImpl implements  UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> findUsersWithConditions(User user) {
        try {
            return userMapper.getUserList(user);  //调用DAO方法进行查询
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public boolean addNewUser(User user) {
        boolean result = false;
        try {
            if (userMapper.add(user) == 1)
                result = true;
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    public UserMapper getUserMapper(){
        return userMapper;
    }

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }
}
